#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"
#include "std_msgs/msg/u_int32.hpp"

using std::placeholders::_1;


class SingleDogNode: public rclcpp:: Node{
public:
    rclcpp::Subscription<std_msgs::msg::String>::SharedPtr sub_novel= this->create_subscription<std_msgs::msg::String>("book", 10, std::bind(&SingleDogNode::novel_callback, this,_1));
    rclcpp::Publisher<std_msgs::msg::UInt32>::SharedPtr pub_money= this->create_publisher<std_msgs::msg::UInt32>("money", 10);

    void novel_callback(const std_msgs::msg::String::SharedPtr novels){
        std_msgs::msg::UInt32 money;
        money.data = 10;
        pub_money->publish(money);

        RCLCPP_INFO(this->get_logger(), "I have read %s.", novels->data.c_str());
    }


    SingleDogNode(std::string name):Node(name) {
        RCLCPP_INFO(this->get_logger(), "hi, I am %s.", name.c_str());
    }

};

int main(int argc, char ** argv){
    rclcpp::init(argc, argv);
    // auto node = std::make_shared<rclcpp::Node>("wang2");
        auto node = std::make_shared<SingleDogNode>("wang2");
    // RCLCPP_INFO(node->get_logger(), "hi, I am wang2.");
    rclcpp::spin(node);
    rclcpp::shutdown();
}
